package com.sdleyou.treepro.business.api.map;

import com.sdleyou.treepro.common.model.dto.WellDTO;
import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.UserMapManager;
import com.sdleyou.treepro.system.version.ApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/api")
public class MapController {
    @Autowired
    private UserMapManager userMapManager;

    @ApiVersion(1)
    @GetMapping("/{version}/map/basic")
    public ResultVO basicMap() {
        return ResultVOUtil.success(userMapManager.basicList());
    }

    @ApiVersion(1)
    @GetMapping("/{version}/map/area/{base_id}")
    public ResultVO areaMap(@PathVariable("base_id") String baseId) {
        return ResultVOUtil.success(userMapManager.areaList(baseId));
    }

    @ApiVersion(1)
    @GetMapping("/{version}/map/region/{area_id}")
    public ResultVO regionMap(@PathVariable("area_id") String areaId,
                              @RequestParam("region_type") @NotEmpty(message = "类型不能为空") String regionType,
                              @RequestParam(name = "page_num", defaultValue = "1") Integer pageNum,
                              @RequestParam(name = "page_size", defaultValue = "5") Integer pageSize) {
        return ResultVOUtil.success(userMapManager.regionList(areaId, regionType, pageNum, pageSize));
    }

    /**
     * 获取坑位列表
     *
     * @param regionId
     * @return
     */
    @ApiVersion(1)
    @GetMapping("/{version}/map/well/{region_id}")
    public ResultVO wellMap(@PathVariable("region_id") String regionId,
                            @RequestParam(name = "page_num", defaultValue = "1") Integer pageNum,
                            @RequestParam(name = "page_size", defaultValue = "5") Integer pageSize,
                            @RequestParam(name = "status", defaultValue = "ALL") String status,
                            @RequestParam(name = "user_id") String userId
    ) {
        return ResultVOUtil.success(userMapManager.wellList(regionId, status, pageNum, pageSize, userId));
    }

    /**
     * 选择坑位
     *
     * @param wellDTO
     * @return
     */
    @ApiVersion(1)
    @PostMapping("/{version}/map/well")
    public ResultVO chooseWell(@RequestBody WellDTO wellDTO) {
        userMapManager.chooseWell(wellDTO);
        return ResultVOUtil.success();
    }

    /**
     * 快捷筛选一个坑位
     *
     * @param userId
     * @return
     */
    @ApiVersion(1)
    @GetMapping("/{version}/map/quick/well")
    public ResultVO quickChooseWell(@RequestParam("user_id") String userId,
                                    @RequestParam("tree_id") String treeId) {
        return ResultVOUtil.success(userMapManager.quickChoose(userId, treeId));
    }

    /**
     * 查看已养成坑位信息
     *
     * @param userId
     * @return
     */
    @ApiVersion(1)
    @PostMapping("/{version}/map/getFinishWell")
    public ResultVO getFinishWell(@RequestParam("user_id") String userId) {
        return ResultVOUtil.success(userMapManager.getFinishWell(userId));
    }

    @ApiVersion(1)
    @GetMapping("/{version}/map/update/orderStatus")
    public ResultVO updateOrderStatus() {
        userMapManager.updateOrderStatus();
        return ResultVOUtil.success();
    }
}
